#include<iostream>
#include<httplib.h>
#include"../comm/log.hpp"
#include"./oj_control.hpp"

using namespace httplib;
using namespace oj_control;
using namespace ns_log;

int main()
{
    std::cout << "1" << std::endl;
    LOG(INFO) << "1" << std::endl;
    Server sev;
    Control col;
    //获取所有的题目
    sev.Get("/all", [&col](const Request &req, Response &resp){
        std::string html;
        col.AllQuestions(&html);
        resp.set_content(html, "text/html; charset=utf-8");
    });

    //获取指定题目
    sev.Get(R"(/questions/(\d+))", [&col](const Request &req, Response &resp){
        std::string number = req.matches[1];
        std::string html;
        col.OneQuestion(number, &html);
        resp.set_content(html, "text/html; charset=utf-8");
    });

    //对题目进行判断
    sev.Get(R"(/judge/(\d+))", [&col](const Request &req, Response &resp){
        std::string number = req.matches[1];
        std::string resault;
        col.Judge(number, resp.body, &resault);
        resp.set_content(resault, "application/json; charset=utf-8");
    });

    sev.set_base_dir("./wwwroot");
    sev.listen("0.0.0.0", 8080);
    return 0;
}